package 
{
import flash.events.FocusEvent;
import flash.geom.Point;
import mx.controls.DataGrid;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.controls.listClasses.IListItemRenderer;
import mx.controls.listClasses.IDropInListItemRenderer;
import mx.core.UIComponent;
import mx.managers.IFocusManagerComponent;
import mx.managers.PopUpManager;

/** 
 *  PopUp TextArea Editor for DataGrid
 */
public class DataGridPopUpEditor extends UIComponent implements IListItemRenderer, IDropInListItemRenderer, IFocusManagerComponent
{

	public function DataGridPopUpEditor()
	{
		super();
	}

	private var popUpEditor:PopUpEditor;
	private var renderer:DataGridItemRenderer;

	

	private var _data:Object;

	public function get data():Object
	{
		return _data;
	}

	public function set data(value:Object):void
	{
		_data = value;
		invalidateProperties();
	}

	private var _listData:BaseListData;

	public function get listData():BaseListData
	{
		return _listData;
	}

	public function set listData(value:BaseListData):void
	{
		_listData = value;
	}

	override public function setFocus():void
	{
		trace("DGPUE.setFocus");
		PopUpManager.addPopUp(popUpEditor, this);

		popUpEditor.owner = this;
		//popUpEditor.setActualSize(owner.width / 2, owner.height / 2);
		//var pt:Point = new Point(width / 2, height / 2);
		//pt.x -= (popUpEditor.width - width) / 2;
		//pt.y -= (popUpEditor.height - height) / 2;
		//pt = localToGlobal(pt);
		//popUpEditor.move(pt.x, pt.y);
		systemManager.activate(popUpEditor);
	}

	override protected function createChildren():void
	{
		super.createChildren();

		renderer = new DataGridItemRenderer();
		addChild(renderer);

        popUpEditor = new PopUpEditor();
	}

	override protected function commitProperties():void
	{
		super.commitProperties();

		renderer.data = data;
		renderer.listData = listData;

	}

	override protected function updateDisplayList(w:Number, h:Number):void
	{
		super.updateDisplayList(w, h);
		renderer.setActualSize(w, h);
	}

}

}